<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<head>
			<meta charset="UTF-8">
			<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
			<title>顾客详情</title>
			<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
			<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
			<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
			 crossorigin="anonymous">
			<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
			 integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> -->

			<link rel="stylesheet" type="text/css" href="../static/dist/css/bootstrap.css" />
		</head>
	<body>
		<style type="text/css">
			body,
			html {
				padding: 0;
				background-color: #F8F8F8;
			}

			.container-fluid {
				padding: 0;
				width: 90%;
				margin: 15px auto 10px;
				border: solid 1px #EFEFEF;
				background-color: #FFFFFF;
				border-radius: 5px;
				overflow: hidden;
				box-shadow: 1px 3px 10px #afafaf;
			}

			.xxxx .container-fluid .top-img {
				width: 100%;
			}

			.xxxx .container-fluid .top-img img {
				width: 100%;
				height: 100%;
				display: block;
			}

			hr {
				margin: 0;
			}

			.xxxx .main {
				width: 90%;
				margin: 15px auto;
				font-size: 14px;
			}

			.xxxx .main .main-span {
				margin: 5px 0;
				opacity: 0.6;
			}

			.btn-primary,
			.btn-default {
				float: right;
				margin: 0 0 15px 15px;
			}
		
			/* 提示框 */
			.alert-success {
				text-align: center;
				position: absolute;
				width: 100%;
				bottom: 0%;
				opacity: 0.95;
			}
		</style>

		<div class="xxxx">

			<div class="container-fluid">
				<div class="top-img">
					<img class="span-img" src="">
				</div>
				<div class="main">
					<div class="main-span">
						<span class="span-name">客户姓名：</span>
						<span class="span-name-val">无数据</span>
					</div>
					<hr>
					<div class="main-span">
						<span class="span-id">客户编号：</span>
						<span class="span-id-val">无数据</span>
					</div>
					<hr>
					<div class="main-span">
						<span class="span-type">客户类型：</span>
						<span class="span-type-val">无数据</span>
					</div>
					<hr>
					
					<div class="main-span">
						<span class="span-qunti">客户群体：</span>
						<span class="span-qunti-val">无数据</span>
					</div>
					<hr>
					<div class="main-span">
						<span class="span-number">到访次数：</span>
						<span><a class="span-number-val" href="javascript:void(0)">无数据</a></span>
					</div>
					<hr>
					<div class="main-span">
						<span class="span-date">最近到访：</span>
						<span class="span-date-val">无数据</span>
					</div>
					<hr>
					<div class="main-span" style="opacity: 0.9 !important;">
						<span class="span-msg">请输入到访记录信息：</span>
						<textarea style="min-width: 100%; max-width: 100%;" class="span-data-val"></textarea>
					</div>
					<br>
					<button type="button" class="btn btn-primary" onclick="submit()">确 定</button>
					<button type="button" class="btn btn-default" onclick="window.history.back()">取 消</button>
				</div>
			</div>
		</div>
		<div class="alert alert-success alert-dismissable hide" role="alert">
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<strong>创建成功</strong>
		</div>
		<div class="alert alert-danger alert-dismissable hide" role="alert">
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<strong>创建成功</strong>
		</div>
	</body>

	<script src="../static/js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../static/dist/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>

	<script type="text/javascript">
		
		function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return decodeURI(r[2]); return null;
		}
		var userId = getUrlParam("userId")
		$(".span-number-val").click(function(){
			window.location.href = "search.html?userId=" + userId
		})
		$.ajax({
			type: 'GET',
			url: "../wechat/note/get/" + userId,
			data: {},
			success: function(resp) {
				if (typeof("sdsd") == typeof(resp) && resp.length < 100) {
					var resp = eval('(' + resp + ')')
				}
				if(resp.code == 100){
					var data_ = resp.data
					console.log(data_)
					$(".span-img").attr("src", data_.imgPath)
					$(".span-name-val").text(data_.userName)
					$(".span-id-val").text(data_.userId)
					$(".span-type-val").text(data_.type)
					$(".span-qunti-val").text(data_.group)
					$(".span-number-val").text("到访" + data_.visitCount + "次")
					$(".span-date-val").text(gettime(data_.recentVisit))
				}else if(resp.code == 302){
					// window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5acca64b07361a8c&redirect_uri=http%3A%2F%2Ftest.aimendian.cn%2Fface%2Fgrant&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
				}
			},
			error: function(error) {
				console.log(error)
			}
		})
		function gettime(t) {
			var _time = new Date(t);
			var year = _time.getFullYear(); //2017
			var month = _time.getMonth() + 1; //7
			var date = _time.getDate(); //10
			if (date.toString().length < 2 && month.toString().length < 2) {
				return year + "-" + "0" + month + "-" + "0" + date; //这里自己按自己需要的格式拼接
			} else if (date.toString().length < 2) {
				return year + "-" + month + "-" + "0" + date; //这里自己按自己需要的格式拼接
			} else if (month.toString().length < 2) {
				return year + "-" + "0" + month + "-" + date; //这里自己按自己需要的格式拼接
			} else {
				return year + "-" + month + "-" + date; //这里自己按自己需要的格式拼接
			}
		}
	
		function submit(){
			if($('.span-data-val').val() == null || $('.span-data-val').val() == ""){
				var detail = "这家伙太懒 啥都没留下"
			}else{
				var detail = $('.span-data-val').val()
			}
			var data = {
				userId: $(".span-id-val").text(),
				detail: detail
			}
			console.log(data)
			data = JSON.stringify(data)
			$.ajax({
				type: 'POST',
				contentType: "application/json;charset=UTF-8",
				dataType: 'json',
				url: "/face/wechat/note/add",
				data: data,
				success: function(resp) {
					if (typeof("sdsd") == typeof(resp) && resp.length < 100) {
						var resp = eval('(' + resp + ')')
					}
					if(resp.code == 101){
						$('.alert-success').removeClass('hide').addClass('in')
						setTimeout(function() {
							$('.alert-success').removeClass('in').addClass('hide')
							window.location.href = "customer.html?state=1&userId=" + $(".span-id-val").text()
						}, 1200)
					}else if(resp.code == 302){
						// window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5acca64b07361a8c&redirect_uri=http%3A%2F%2Ftest.aimendian.cn%2Fface%2Fgrant&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
					}
					console.log(resp)
				},
				error: function(error) {
					console.log(error)
				}
			})
		}
	</script>
	</body>
</html>
